import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-10-02
 * Time: 13:22
 */
public class IODemon10 {
    public static void main(String[] args) throws IOException {
        try(InputStream inputStream = new FileInputStream("./test.txt")){
            while (true){
                //也可以一次读若干个字节,buffer(缓冲区)
                byte[] buffer = new byte[1024];//读的时候会尝试把buffer[1024]填满
                int n = inputStream.read(buffer);//传入的参数是buffer数组，方法内部对数组内容进行修改后，方法外部也能生效
                if (n == -1){
                    break;
                }
                String string = new String(buffer , 0 , n);//构造一个String对象，数组前n个字节来构造

                    System.out.printf(string);//遍历数组，并打印
            }
        }
    }
}


